﻿using System;
using System.Collections.Generic;
using System.Text;

namespace MapDrawer
{
    public abstract class Way
    {
        /// <summary>
        /// A list of the nodes defining the polygon.
        /// </summary>
        public List<Node> Nodes { get; set; }

        /// <summary>
        /// The numer of nodes defining the polygon.
        /// </summary>
        public int NodesCount
        {
            get { return Nodes.Count; }
        }

        /// <summary>
        /// Initializes a new empty way.
        /// A way is a form (a polygon) to display on the map.
        /// </summary>
        protected Way()
        {
            Nodes = new List<Node>();
        }

        /// <summary>
        /// Adds a node to define the polygon.
        /// The new node will be added at the end of the existing list.
        /// </summary>
        /// <param name="n">The node to add.</param>
        public void AddNode(Node n)
        {
            Nodes.Add(n);
        }

        public float[] ToFloats()
        {
            float[] tab = new float[NodesCount *2];
            int i = 0;
            Nodes.ForEach(n =>
            {
                tab[i++] = (float)n.Coordinates.Longitude;
                tab[i++] = (float)n.Coordinates.Latitude;
            });
            return tab;
        }

    }
}
